capture log close
cd "mypath\sandbox/"					// adjust the path to run the code
log using "master_log.log", replace
*========================================================================================*

******************************************************************************************
* Project name: The Effects of Immigration on Places and People
* Do-file name:	master.do                          
* Task:         master do-file runs all other project do-files    
* Last change:  03.09.2025   
******************************************************************************************


******************************************************************************************
*** program setup
******************************************************************************************

version 14.2
clear all
macro drop _all
set linesize 90
set more off
* set trace on
discard
set seed 123456789


******************************************************************************************
*** create folders
******************************************************************************************
// assuming that the folder "sandbox" and its subfolder "do-files" exists

shell mkdir "do-files\data_analysis"
shell mkdir "do-files\data_management"

shell mkdir "figures"
shell mkdir "tables"
shell mkdir "tables\employ"
shell mkdir "tables\price_effect"
shell mkdir "tables\wage"

shell mkdir "data"
shell mkdir "data\orig"
shell mkdir "data\bootstrap"

shell mkdir "data\bootstrap\emp_app"
shell mkdir "data\bootstrap\emp_app\1991_cz_shock"

shell mkdir "data\bootstrap\emp_decomp"
shell mkdir "data\bootstrap\emp_decomp\1991_cz_shock"

shell mkdir "data\bootstrap\non_emp"
shell mkdir "data\bootstrap\pseudo_panel"

shell mkdir "data\bootstrap\occ_upg"
shell mkdir "data\bootstrap\occ_upg\1991_cz_shock"

shell mkdir "data\bootstrap\price_effect"
shell mkdir "data\bootstrap\price_effect\1991_cz_shock"

shell mkdir "data\bootstrap\wage_decomp"
shell mkdir "data\bootstrap\wage_decomp\1991_cz_shock"


******************************************************************************************
*** data management do-files
******************************************************************************************

*------- A) create input data -----------------------------------------------------------*

** 1)
do "do-files\data_management/cr_consistenteduc.do"			// creates consistent education variable

** 2)
do "do-files\data_management/cr_impute_genmeans.do"			// creates controls for wage imputation
	* 2.1)
	* "cr_prepare_variables_genmeans_ado.do"	 			// prepares variables for wage imputation

** 3)
do "do-files\data_management/cr_impute_tobits.do"	   		// generates imputed wages
	* 3.1)
	* "cr_impute_prepare_variables_ado.do"	 				// prepares variables for wage imputation
		* 3.1.1)
		* "cr_generate-AMR50_ado.do"						// creates 50 commuting zones for the wage imputation

** 4)
do "do-files\data_management/cr_impute_education.do"		// creates imputed education variable

** 5)
do "do-files\data_management/cr_tasks.do"					// creates tasks variables on occupational level


*------- B) create analysis sample ------------------------------------------------------*

** 1) 
do "do-files\data_management/cr_unempl_data.do"				// create unemployment data

** 2) 
do "do-files\data_management/cr_treat_control_sample.do"	// create treatment and control sample for the years 1980-2000

** 3)
do "do-files\data_management/cr_prepare_map.do"				// creates distance to border variable used for the IV																

** 4)
do "do-files\data_management/cr_clean_data.do"				// clean variables, merge imputed education, imputed wages, and distance to sample
	* 4.1)
	* "cr_real_wages_ado.do"								// sub-routine to create wage including censoring limits, and to create real wages	

** 5)
do "do-files\data_management/cr_region_data.do"				// creates analysis data
	* 5.1)
	* "cr_dec_emp_groups_ado.do"							// sub-routine to generate groups for decomposition
	* 5.2)
	* "cr_pseudo_panel_ado.do"								// sub-routine to generate samples for pseudo-panel regressions 


******************************************************************************************
*** analysis do-files
******************************************************************************************

** 1)
do "do-files\data_analysis/an_desc_stats_01.do"				// creates descriptive statistics (Table A.3)

** 2)
do "do-files\data_analysis/an_reg_first_stage.do"			// runs first stage regressions (Table A.2) and creates Figure A.3

** 3)
do "do-files\data_analysis/an_dec_employ_01.do"				// runs employment decomposition (Figure 1 & Table 1), runs employment decomposition by task and age group (Table 3 & 4, Figure 2)

** 4)
do "do-files\data_analysis/an_dec_employ_02.do"				// runs employment regressions for non-employed workers (Table 3)

** 5)
do "do-files\data_analysis/an_reg_occupg_task.do"			// runs regression on share of task group employment (Figure 2)

** 6)
do "do-files\data_analysis/an_reg_employ_01.do"				// runs regressions on apprenticeships employment (Figure 3)

** 7)
do "do-files\data_analysis/an_dec_wage_01.do"				// runs wage decomposition (Figure 1, Table 2, Table A.4)

** 8)
do "do-files\data_analysis/an_reg_wage_indv_01.do"			// estimates pure wage effect (Figure 1, Table 2, Table A.4), estimates pure wage effect by task and age group (Table 3)

** 9)
do "do-files\data_analysis/an_reg_wage_indv_02.do"			// estimates age selection coefficient (Table 2)

** 10)
do "do-files\data_analysis/an_reg_wage_indv_03.do"			// estimates pure wage effect for non-employed workers (Table 3)

** 11)
do "do-files\data_analysis/an_reg_wage_pseudo_panel.do"		// runs regressions on wage growth on the pseudo-panel (Table A.4)


******************************************************************************************
*** correlation analysis based on SIAB data
******************************************************************************************

** 1) 
do "do-files\data_management/cr_data_siab_01.do"			// prepares siab data

** 2) 
do "do-files\data_management/cr_data_siab_02.do"			// creates sample for correlation analysis

** 3) 
do "do-files\data_analysis/an_data_siab_01.do"				// restricts sample and runs correlation analysis (Table A.1)


******************************************************************************************
*** end
******************************************************************************************

log close
exit


*========================================================================================*
Comments:
-
